package com.oa.demo.auth.config;

import com.oa.demo.auth.properties.AuthProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;

/**
 * 资源适配器
 * @author 孔德成
 * @date 2020/11/20 15:27
 */
@Configuration
@EnableResourceServer
public class OaResourceServerConfigurerAdapter extends ResourceServerConfigurerAdapter {

    @Autowired
    private AuthProperties properties;

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
        super.configure(resources);
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
                .requestMatchers().antMatchers("/**")
                .and()
                .authorizeRequests()
                .antMatchers(properties.getAnonUrl()).permitAll()
                .antMatchers("/**").authenticated();
    }
}
